﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web.Mvc;
using System.Web;

namespace timetableasy.Models
{
    public class PeriodRepository
    {
        private TimeTableDBDataContext db = new TimeTableDBDataContext();

        //Query Methods
        public IQueryable<Period> FindAllPeriods()
        {
            return db.Periods;
        }

        public Period GetPeriodById(int id)
        {
            return db.Periods.SingleOrDefault(p => p.PeriodId == id);
        }

        //Insert/Delete Methods

        public void Add(Period period)
        {
            db.Periods.InsertOnSubmit(period);
        }

        public void Delete(Period period)
        {
            db.Periods.DeleteOnSubmit(period);
        }

        //Persistence

        public void Save()
        {
            db.SubmitChanges();
        }
    }
}